package org.origin.centre.support.mapper;

import org.origin.centre.support.utils.BasicUtil;
import org.springframework.jdbc.core.ColumnMapRowMapper;

import java.util.Locale;

/**
 * 转驼峰 ColumnMapRowMapper
 *
 * @author ferret
 * @version 2024-05-08
 */
@SuppressWarnings("unused")
public class CamelCaseColumnMapRowMapper extends ColumnMapRowMapper {

    @Override
    protected String getColumnKey(String columnName) {
        if (columnName.contains("_") ||
                columnName.contains("-")) {
            // 转驼峰
            columnName = columnName.replaceAll(BasicUtil.escapeWord("-"), "_");
            columnName = columnName.toLowerCase(Locale.ROOT);
            return BasicUtil.toCamelCase(columnName);
        }
        return super.getColumnKey(columnName);
    }

}
